
from world import town

GUESS_PRICE = 50

class WorldModel(object):
    """
    A model of a world.  This represents an imperfect knowledge of a world and
    its information.
    """
    
    def __init__(self):
        self.values = {}
    
    def store_value(self, entity, value):
        """
        Stores the percieved value of a object in the world, the type and
        characteristics of the object stored is up to the user to ensure it is
        correct.
        entity - The object to assign value to.  Must be hashable.
        value - The value to attach to the entity.
        """
        self.values[entity] = value    
        


def get_optimistic_model(world):
    model = WorldModel()
    world.to_all_towns(_guess_prices, [model])
    world.to_all_routes(_optimistic_costs, [model])
    return model
    
    
def _guess_prices(t, model):
    for good in town.ALL_GOODS:
        model.store_value((t, good), 50)
        
def _optimistic_costs(r, model):
    model.store_value(r, 0)